<%@ Control Language="c#" Inherits="CRM.InvoiceManagement.Payments.AllocationsView" Codebehind="AllocationsView.ascx.cs" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajaxToolkit" %>

<script type="text/javascript">
var sSelectNameUserContext = '';
function ChangeInvoice(sPARENT_ID, sPARENT_NAME)
{
	var fldINVOICE_NAME = document.getElementById(sSelectNameUserContext + 'INVOICE_NAME');
	if ( fldINVOICE_NAME != null )
	{
		fldINVOICE_NAME.value = sPARENT_NAME;
		ItemNameChanged('<%= GetCurrencyControl() != null ? CURRENCY_ID.ClientID : "" %>', fldINVOICE_NAME);
	}
}
function InvoicePopup(fldSELECT_NAME)
{
	sSelectNameUserContext = fldSELECT_NAME.id.replace('SELECT_NAME', '');
	var sINVOICE_NAME = '';
	var fldINVOICE_NAME = document.getElementById(sSelectNameUserContext + 'INVOICE_NAME');
	if ( fldINVOICE_NAME != null )
	{
		sINVOICE_NAME = fldINVOICE_NAME.value;
	}
	var fldACCOUNT_ID = document.getElementById('<%= new DynamicControl(this.Parent as CRMControl, "ACCOUNT_ID").ClientID %>');
	window.open('../Invoices/Popup.aspx?ACCOUNT_ID=' + fldACCOUNT_ID.value + '&ClearDisabled=1&NAME=' + escape(sINVOICE_NAME),'InvoicePopup','width=600,height=400,resizable=1,scrollbars=1');
	return false;
}
</script>

<div id="divAllocationsView">
    <asp:GridView ID="grdMain" AutoGenerateColumns="false" AllowPaging="true" AllowSorting="false"
        AutoGenerateEditButton="false" AutoGenerateDeleteButton="false" OnRowCreated="grdMain_RowCreated"
        OnRowDataBound="grdMain_RowDataBound" OnRowEditing="grdMain_RowEditing" OnRowDeleting="grdMain_RowDeleting"
        OnRowUpdating="grdMain_RowUpdating" OnRowCancelingEdit="grdMain_RowCancelingEdit"
        Width="100%" runat="server">
        <RowStyle CssClass="oddListRowS1" VerticalAlign="Top" />
        <AlternatingRowStyle CssClass="evenListRowS1" VerticalAlign="Top" />
        <HeaderStyle CssClass="listViewThS1" />
        <Columns>
            <asp:TemplateField HeaderText="Payments.LBL_LIST_INVOICE_NAME" ItemStyle-Width="30%"
                HeaderStyle-Wrap="false">
                <ItemTemplate>
                    <%# Eval("INVOICE_NAME") %>
                </ItemTemplate>
                <EditItemTemplate>
                    <asp:HiddenField ID="ID" Value='<%# Eval("ID"          ) %>' runat="server" />
                    <asp:HiddenField ID="INVOICE_ID" Value='<%# Eval("INVOICE_ID"  ) %>' runat="server" />
                    <asp:HiddenField ID="PREVIOUS_NAME" Value='<%# Eval("INVOICE_NAME") %>' runat="server" />
                    <asp:HiddenField ID="AMOUNT_DUE_USDOLLAR" Value='<%# TypeConvert.ToDecimal(Eval("AMOUNT_DUE_USDOLLAR")).ToString("0.000") %>'
                        runat="server" />
                    <asp:HiddenField ID="AMOUNT_USDOLLAR" Value='<%# TypeConvert.ToDecimal(Eval("AMOUNT_USDOLLAR"    )).ToString("0.000") %>'
                        runat="server" />
                    <nobr>
                        <asp:TextBox ID="INVOICE_NAME" Text='<%# Eval("INVOICE_NAME") %>' TabIndex="12" onblur=<%# "ItemNameChanged('" + (GetCurrencyControl() != null ? CURRENCY_ID.ClientID : "") + "', this);" %>
                            autocomplete="off" runat="server" />
                        <asp:Button ID="SELECT_NAME" OnClientClick="return InvoicePopup(this);" CssClass="button"
                            Text='<%# Translation.GetTranslation.Term(".LBL_SELECT_BUTTON_LABEL") %>' ToolTip='<%# Translation.GetTranslation.Term(".LBL_SELECT_BUTTON_TITLE") %>'
                            runat="server" />
                    </nobr>
                    <ajaxToolkit:AutoCompleteExtender ID="autoNAME" TargetControlID="INVOICE_NAME" ServiceMethod="InvoiceNameList"
                        ServicePath="~/CRM/Invoices/AutoComplete.asmx" MinimumPrefixLength="2" CompletionInterval="250"
                        EnableCaching="true" CompletionSetCount="12" runat="server" />
                </EditItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Payments.LBL_LIST_AMOUNT_DUE" ItemStyle-Width="25%"
                HeaderStyle-Wrap="false">
                <ItemTemplate>
                    <%# TypeConvert.ToDecimal(Eval("AMOUNT_DUE")).ToString("c") %>
                </ItemTemplate>
                <EditItemTemplate>
                    <asp:TextBox ID="AMOUNT_DUE" Text='<%# TypeConvert.ToDecimal(Eval("AMOUNT_DUE")).ToString("0.00") %>'
                        Width="60" TabIndex="17" ReadOnly="true" autocomplete="off" runat="server" />
                </EditItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Payments.LBL_LIST_ALLOCATED" ItemStyle-Width="25%"
                HeaderStyle-Wrap="false">
                <ItemTemplate>
                    <%# TypeConvert.ToDecimal(Eval("AMOUNT")).ToString("c") %>
                </ItemTemplate>
                <EditItemTemplate>
                    <asp:TextBox ID="AMOUNT" Text='<%# TypeConvert.ToDecimal(Eval("AMOUNT")).ToString("0.00") %>'
                        Width="60" TabIndex="17" autocomplete="off" runat="server" />
                </EditItemTemplate>
            </asp:TemplateField>
            <asp:CommandField ButtonType="Button" ShowEditButton="true" ShowDeleteButton="true"
                ControlStyle-CssClass="button" EditText=".LBL_EDIT_BUTTON_LABEL" DeleteText=".LBL_DELETE_BUTTON_LABEL"
                UpdateText=".LBL_UPDATE_BUTTON_LABEL" CancelText=".LBL_CANCEL_BUTTON_LABEL" ItemStyle-Width="10%" />
        </Columns>
    </asp:GridView>
    <asp:Label ID="lblLineItemError" ForeColor="Red" EnableViewState="false" runat="server" />
    <span id="AjaxErrors" style="color: Red"></span>
    <asp:UpdateProgress ID="UpdateProgressEditViewPanel" runat="server" AssociatedUpdatePanelID="ctlSummaryPanel">
        <ProgressTemplate>
            <div id="loader" class="loader" align="center">
                <img src="<%=ResolveUrl("~/CRM/image/loading-spinner.gif") %>" alt="Loading..." /><span
                    id="loaderText" class="loaderText">Loading...</span>
            </div>
        </ProgressTemplate>
    </asp:UpdateProgress>
    <asp:UpdatePanel ID="ctlSummaryPanel" runat="server">
        <ContentTemplate>
            <asp:Table SkinID="tabForm" runat="server">
                <asp:TableRow>
                    <asp:TableCell>
                        <asp:HiddenField ID="ALLOCATED_USDOLLAR" runat="server" />
                        <asp:HiddenField ID="EXCHANGE_RATE" runat="server" />
                        <asp:Table ID="tblSummary" SkinID="tabDetailView" runat="server">
                            <asp:TableRow>
                                <asp:TableCell Width="65%">&nbsp;</asp:TableCell>
                                <asp:TableCell Width="15%" CssClass="dataLabel">
                                    <asp:Label ID="LBL_ALLOCATED" Text='<%# Translation.GetTranslation.Term("Payments.LBL_ALLOCATED") %>' runat="server" /></asp:TableCell>
                                <asp:TableCell Width="20%" CssClass="dataField">
                                    <asp:TextBox ID="ALLOCATED" ReadOnly="true" BackColor="#dddddd" runat="server" /></asp:TableCell>
                            </asp:TableRow>
                        </asp:Table>
                    </asp:TableCell>
                </asp:TableRow>
            </asp:Table>
        </ContentTemplate>
    </asp:UpdatePanel>
</div>
